package com.akol.seret;

import android.os.AsyncTask;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.akol.seret.utils.C;

import org.json.JSONObject;


public class MainActivity extends ActionBarActivity {

    private TextView httpStuff;
    private Button postButton;
    private EditText movieNameInput;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        httpStuff = (TextView) findViewById(R.id.data_viewer);
        postButton = (Button) findViewById(R.id.button_post);
        movieNameInput = (EditText) findViewById(R.id.input_movie_name);

        postButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new Post().execute();
            }
        });
    }


    class Post extends AsyncTask<Void, Void, String> {

        protected void onPostExecute(String returned) {
            httpStuff.setText(returned);
        }

        @Override
        protected String doInBackground(Void... params) {
            PostMethod test = new PostMethod();

            JSONObject returned = null;
            String movieName = movieNameInput.getText().toString();
            returned = test.postData(C.URL, movieName);

            if (returned != null) {
                return returned.toString();
            } else {
                return "FUCKING FAILURE";
            }

        }
    }

}
